﻿@model WaiGaoQiaoWeb.Models.CardRechargeVM
@{
    ViewBag.Title = "CardRechargeIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm")
    @Html.Css("dp")
    <script type="text/javascript" language="javascript">
        var maiheight = document.documentElement.clientHeight;
        $(document).ready(function () {
            $("#txtCardEmpNo").focus();
            $("#btnSave").click(function (event) {
                if (!$("#fmEdit").valid()) {
                    return false;
                }
                var allvalue = "";
                if ($("#HiddenEmpNo").val() == "") {
                    showLoadingMsg("请刷卡!", { left: 500, top: 6 }, true, 3000);
                    return false;
                }
                if ($("#money").val() == "") {
                    showLoadingMsg("请输入充值金额!", { left: 500, top: 6 }, true, 3000);
                    return false;
                }
                $('#fmEdit').ajaxSubmit(function (callback) {
                    if (callback) {
                        showLoadingMsg("增款成功!", { left: 500, top: 6 }, true, 3000);
                        $("#CardTable").flexOptions(option).flexReload();
                        document.getElementById("EmpNo").value = "";
                        document.getElementById("DeptName").value = "";
                        document.getElementById("Name").value = "";
                        document.getElementById("Balance").value = "";
                        document.getElementById("HiddenEmpNo").value = "";
                        document.getElementById("txtCardEmpNo").value = "";
                        document.getElementById("money").value = "";
                        $("#txtCardEmpNo").focus();
                        return false;
                    }
                    else {
                        showLoadingMsg("增款失败!", { left: 500, top: 6 }, true, 3000);
                        return false;
                    }
                });
            });
            var otherpm = $("#title").height();
            var gh = maiheight - otherpm - 80;
            var option = {
                height: 240,
                width: 740,
                url: '@Url.Action("GetList")',
                colModel: [
                    { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '时间', name: 'DateTime', width: 100, sortable: false, hide: false, align: 'left' },
			        { display: '部门', name: 'DeptName', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '人员编号', name: 'EmpNo', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '姓名', name: 'Name', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '充值金额', name: 'ConMoney', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '充值后余额', name: 'Balance', width: 100, sortable: false, hide: false, align: 'left' }
				],
                singleselected: true,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 20,
                rpOptions: [10, 15, 20],
                showcheckbox: true,
                rowbinddata: true,
                query: ''
            };
            var grid = $("#CardTable").flexigrid(option);
            $("#txtCardEmpNo").bind('keydown', function (e) {
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    select();
                }
            });
        });
        function select() {
            var vcardempno = $("#txtCardEmpNo").val();
            if (vcardempno == "") {
                showLoadingMsg("请输入卡号或工号!", { left: 500, top: 6 }, true, 3000);
                $("#txtCardEmpNo").focus();
                return;
            }
            var query = vcardempno;
            var rowcount = 0;
            $.ajax({
                type: "POST",
                url: '@Url.Action("GetInfo")',
                data: { Select: query },
                dataType: "json",
                async: true,
                success: function (data) {
                    if (data.EmpNo != null) {
                        document.getElementById("EmpNo").value = data.EmpNo;
                        document.getElementById("DeptName").value = data.DeptName;
                        document.getElementById("Name").value = data.Name;
                        document.getElementById("Balance").value = data.Balance;
                        document.getElementById("HiddenEmpNo").value = data.EmpNo;
                        $("#money").focus();
                    }
                    else {
                        showLoadingMsg("没有此卡号或工号!", { left: 500, top: 6 }, true, 3000);
                        document.getElementById("EmpNo").value = "";
                        document.getElementById("DeptName").value = "";
                        document.getElementById("Name").value = "";
                        document.getElementById("Balance").value = "";
                        document.getElementById("HiddenEmpNo").value = "";
                        document.getElementById("money").value = "";
                        $("#txtCardEmpNo").focus();
                    }
                },
                error: function () { }
            });
        }
    </script>
}
@using (Html.BeginForm("SaveIncreaseMoney", "CardRecharge", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.HiddenEmpNo)
    <div class="mainpanel">
        <table cellpadding="0" cellspacing="0" style="width: 100%; height: auto">
            <tr>
                <td style="width: 100%">
                    <table cellpadding="0" cellspacing="6" style="height: auto">
                        <tr>
                            <td>
                                卡号/工号：@Html.TextBox("txtCardEmpNo", "", new { @style = "width:120px;" })
                            </td>
                            <td>
                                <a id="butfind" class="button" href="javascript:void(0);" onclick="select();"><span>
                                    查询</span></a>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="width: 100%">
                    <table cellpadding="0" cellspacing="6" style="width: 100%; height: auto">
                        <tr>
                            <td>
                                &nbsp;部门名称：@Html.TextBoxFor(model => model.DeptName, new { @readonly = true, disabled = "disabled" })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;人员工号：@Html.TextBoxFor(model => model.EmpNo, new { @readonly = true, disabled = "disabled" })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;人员姓名：@Html.TextBoxFor(model => model.Name, new { @readonly = true, disabled = "disabled" })
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;卡内余额：@Html.TextBoxFor(model => model.Balance, new { @readonly = true, disabled = "disabled" })
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="width: 100%">
                    <table cellpadding="0" cellspacing="6" style="height: auto">
                        <tr>
                            <td style="height: 50px">
                                &nbsp;充值金额：@Html.TextBoxFor(model => model.money, new { Class = "uc1", @style = "width:120px;height:40px" })
                                @Html.ValidationMessageFor(model => model.money)
                            </td>
                            <td>
                                <a id="btnSave" href="javascript:void(0);" class="button"><span>保存</span></a>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="width: 100%">
                    <table id="CardTable" style="display: none;">
                    </table>
                </td>
            </tr>
        </table>
    </div>
}
